package com.ruoyi.project.base.unitInfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.base.unitInfo.domain.UnitInfo;
import com.ruoyi.project.base.unitInfo.service.IUnitInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 所属单位Controller
 * 
 * @author ruoyi
 * @date 2021-01-23
 */
@Controller
@RequestMapping("/base/unitInfo")
public class UnitInfoController extends BaseController
{
    private String prefix = "base/unitInfo";

    @Autowired
    private IUnitInfoService unitInfoService;

    @RequiresPermissions("base:unitInfo:view")
    @GetMapping()
    public String unitInfo()
    {
        return prefix + "/unitInfo";
    }

    /**
     * 查询所属单位列表
     */
    @RequiresPermissions("base:unitInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UnitInfo unitInfo)
    {
        startPage();
        List<UnitInfo> list = unitInfoService.selectUnitInfoList(unitInfo);
        return getDataTable(list);
    }

    /**
     * 导出所属单位列表
     */
    @RequiresPermissions("base:unitInfo:export")
    @Log(title = "所属单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UnitInfo unitInfo)
    {
        List<UnitInfo> list = unitInfoService.selectUnitInfoList(unitInfo);
        ExcelUtil<UnitInfo> util = new ExcelUtil<UnitInfo>(UnitInfo.class);
        return util.exportExcel(list, "unitInfo");
    }

    /**
     * 新增所属单位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存所属单位
     */
    @RequiresPermissions("base:unitInfo:add")
    @Log(title = "所属单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UnitInfo unitInfo)
    {
        return toAjax(unitInfoService.insertUnitInfo(unitInfo));
    }

    /**
     * 修改所属单位
     */
    @GetMapping("/edit/{unitId}")
    public String edit(@PathVariable("unitId") Long unitId, ModelMap mmap)
    {
        UnitInfo unitInfo = unitInfoService.selectUnitInfoById(unitId);
        mmap.put("unitInfo", unitInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存所属单位
     */
    @RequiresPermissions("base:unitInfo:edit")
    @Log(title = "所属单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UnitInfo unitInfo)
    {
        return toAjax(unitInfoService.updateUnitInfo(unitInfo));
    }

    /**
     * 删除所属单位
     */
    @RequiresPermissions("base:unitInfo:remove")
    @Log(title = "所属单位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(unitInfoService.deleteUnitInfoByIds(ids));
    }
}
